package com.own.business.question.business.service.impl;

import com.own.business.question.business.service.QuestionOptionService;
import com.own.business.question.entity.bo.QuestionOptionBo;
import com.own.business.question.entity.map.QuestionOptionMapVo;
import com.own.business.question.entity.po.QuestionOption;
import com.own.business.question.entity.query.QuestionOptionQuery;
import com.own.business.question.entity.vo.QuestionOptionVo;
import com.own.business.question.mapper.QuestionOptionMapper;
import com.own.component.common.base.service.impl.AbstractBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * QuestionOptionServiceImpl
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/05/14 09:41:05
 * @since 4.0.0
 */
@Slf4j
@Service
public class QuestionOptionServiceImpl extends AbstractBaseService<
        QuestionOption,
        QuestionOptionBo,
        QuestionOptionVo,
        QuestionOptionMapVo,
        QuestionOptionQuery,
        QuestionOptionMapper
        > implements QuestionOptionService {


    /**
     * 添加选项信息
     *
     * @param questionId         题目id
     * @param questionOptionList 选项列表
     * @return 添加完后的列表
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<QuestionOption> addPoBatch(Long questionId, List<QuestionOptionBo> questionOptionList) {
        var optionList = questionOptionList.stream()
                .map(QuestionOptionBo::toPo)
                .peek(option -> option.setFkQuestionId(questionId))
                .toList();
        addPoBatch(optionList);
        return optionList;
    }
}
